import tarfile
import os,sys,shutil,time

print('--> enter python untargz script...')

def untar(fname, dirs):
    t = tarfile.open(fname)
    t.extractall(path = dirs) 
    t.close()

if __name__ == "__main__":
    tar_file_dir = sys.argv[1]

    for p in os.listdir(tar_file_dir):
        if p.endswith("gz"):
            tar_file = tar_file_dir + os.sep + p
            tar_dir = tar_file.split('.')[0]
            if not os.path.exists(tar_dir):
                os.mkdir(tar_dir)
            untar(tar_file, tar_dir)